package com.xinqi.modules.exam.common.controller;

import com.xinqi.common.base.response.R;
import com.xinqi.modules.exam.common.delayed.ExamDelayQueueService;
import com.xinqi.modules.exam.common.delayed.ExamTopicEventService;
import com.xinqi.modules.exam.common.enums.ExamQueueEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author linkai
 * @date 2023/11/28
 */
@RestController
@RequestMapping("/tools")
@RequiredArgsConstructor
public class MqToolController {
    private final ExamDelayQueueService examDelayQueueService;
    private final ExamTopicEventService examTopicEventService;

    @GetMapping("/publish-task")
    public R<Boolean> addDelayTask(String examQueue, Long examId, LocalDateTime dateTime) {
        examDelayQueueService.publishTask(ExamQueueEnum.of(examQueue), examId, dateTime);
        return R.ok(true);
    }

    @GetMapping("/remover-task")
    public R<Boolean> removerTask(String examQueue, Long examId) {
        examDelayQueueService.removerTask(ExamQueueEnum.of(examQueue), examId);
        return R.ok(true);
    }

    @GetMapping("/update-task")
    public R<Boolean> updateTask(String examQueue, Long examId, LocalDateTime dateTime) {
        examDelayQueueService.updateTask(ExamQueueEnum.of(examQueue), examId, dateTime);
        return R.ok(true);
    }

    @GetMapping("/add-event")
    public R<Boolean> addEvent(String examQueue, Long examId, LocalDateTime dateTime) {
        examTopicEventService.publishEvent(ExamQueueEnum.of(examQueue), examId);
        return R.ok(true);
    }
}
